package com.moyuxi.sound_of_the_forest.ui.compose

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material.icons.filled.Search
import androidx.compose.material3.CenterAlignedTopAppBar
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MyTopAppBarCompose(
    visible: Boolean = true,
    title: String = "",
    navIconIsMenu: Boolean = true,
    navClick: () -> Unit = {},
    actionVisible: Boolean = false,
    actionClick: () -> Unit = {},
    other: @Composable () -> Unit = {},
) {
    val appbarModifier = Modifier.size(36.dp)
    Column(modifier = Modifier.fillMaxWidth()) {
        // 标题栏
        if (visible) {
            CenterAlignedTopAppBar(
                title = { Text(text = title) },
                navigationIcon = {
                    if (navIconIsMenu) Icon(Icons.Default.Menu,
                        "菜单",
                        modifier = Modifier
                            .then(appbarModifier)
                            .clickable { navClick.invoke() })
                    else Icon(Icons.Default.ArrowBack,
                        "返回",
                        Modifier
                            .then(appbarModifier)
                            .clickable { navClick.invoke() })

                },
                actions = {
                    if (actionVisible) Icon(Icons.Default.Search,
                        "搜素",
                        modifier = Modifier
                            .then(appbarModifier)
                            .clickable { actionClick.invoke() })

                },
                colors = TopAppBarDefaults.centerAlignedTopAppBarColors(MaterialTheme.colorScheme.primaryContainer),
            )
        }
        //标题栏下方内容
        other()
    }

}